package com.lyt.dao;

import com.lyt.bean.LinkAnswer;
import com.lyt.bean.TestAnswer;
import com.lyt.vo.TestAnswerVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author:张勇
 * @Date：2023/5/18 10:47
 * @Info:
 */
@Repository
public interface TestAnswerDao {

    @Insert("insert into test_answer (stu_test_id,paper_id,linkAnswers) " +
            "values(#{stu_test_id},#{paper_id},#{linkAnswers})")
    public void addAnswer(TestAnswer testAnswer);

    @Insert("insert into link_answer (_index,question_id,answer) " +
            "values(#{_index},#{questionId},#{answer})")
    @SelectKey( keyProperty="id", keyColumn = "id",before=false, resultType=int.class,statement="select last_insert_id()")
    public void addLinkAnswer(LinkAnswer linkAnswer);

    @Select("select * from link_answer where id = #{id} ")
    public LinkAnswer selAnswerById(@Param("id")Integer id);

    @Delete("delete from link_answer where id = #{id} ")
    public Integer delAnswerById(@Param("id")Integer id);

    //根据学生id和试卷id找到考试答案表主表的所有数据
    @Select("select linkAnswers from test_answer where stu_test_id = #{stu_id} and paper_id = #{paper_id}")
    public String selLinkAnswerByStuIdAndPaperId(@Param("stu_id") Integer stu_id,@Param("paper_id") Integer paper_id);

    //根据学生id和试卷id找到考试答案表主表的id
    @Select("select test_id from test_answer where stu_test_id = #{stu_id} and paper_id = #{paper_id}")
    public Integer selTestAnswerIdByStuIdAndPaperId(@Param("stu_id") Integer stu_id,@Param("paper_id") Integer paper_id);

    //更新学生考试的答案
    @Update("update test_answer set linkAnswers = #{answer} where test_id = #{id}")
    public void updateAnswer(@Param("answer") String answer,@Param("id") Integer id);
}
